package com.example.building_material_mannager.service.impl;

import com.example.building_material_mannager.entity.Collectionls;
import com.example.building_material_mannager.entity.Sell;
import com.example.building_material_mannager.mapper.CollectionlsMapper;
import com.example.building_material_mannager.mapper.SellMapper;
import com.example.building_material_mannager.service.SellService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SellServiceImpl implements SellService {
    @Resource
    SellMapper sellMapper;
    @Resource
    CollectionlsMapper collectionlsMapper;

    @Override
    public List<Sell> select(Sell sell) {
        List<Sell> sells=sellMapper.select(sell);
        return sells;
    }

    @Override
    public Sell selectByOrder(String sordernumber) {
        Sell sell=sellMapper.selectByOrder(sordernumber);
        return sell;
    }


    @Transactional
    @Override
    public boolean add(Sell sell) {
        boolean addSell=sellMapper.add(sell);
        Collectionls collectionls=new Collectionls(null,"纸质","未支付",null,sell.getSordernumber());
        boolean addCollectionls=collectionlsMapper.addCollectionls(collectionls);
        if(addSell && addCollectionls){
           return true;
        }
        return false;
    }


    @Override
    public boolean delete(String sordernumber) {
        boolean re=sellMapper.delete(sordernumber);
        return re;
    }

    @Override
    public boolean update(Sell sell) {
        boolean re=sellMapper.update(sell);
        return re;
    }
}
